﻿using Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using FluentAssertions;
using WikiBugtracker.Settings;
using System.IO;
using System.ComponentModel;

namespace WikiBugtracker.Test
{
    
    
    /// <summary>
    ///This is a test class for SerializerTest and is intended
    ///to contain all SerializerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SerializerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for SerializeObject
        ///</summary>
        [TestMethod()]
        public void SerializeObjectTest()
        {
            MySettingsManager target = new MySettingsManager();
            target.Folder = "C:\\";
            target.FullName = "Pier-Luc Duchaine";
            target.Username = Environment.UserName;
            target.Add("key1", "value1", true);

            String parameters = target.ToString();

            string file_path = "H:\\test_serialize.xml";

            Serializer.SerializeObject(target, file_path);
            target = (MySettingsManager)Serializer.DeserializeObject(file_path, typeof(MySettingsManager));

            parameters.Should().Be(target.ToString());


            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            FileInfo filename = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);

            Console.WriteLine(path);
            Console.WriteLine(string.Format("{0}.{1}.xml", filename.Name.Substring(0, filename.Name.Length - filename.Extension.Length), this.GetType().Name));
        }

        [TestMethod()]
        public void RunFalseTest()
        {
            MySettingsManager target = new MySettingsManager();
            //bob(target);

            TestAccessor.Should().Be("Patate");
        }

        [DefaultValue("Patate")]
        public string TestAccessor { get; set; }

        void bob(object obj)
        {
            string.Empty.Should().Be(obj.GetType().ToString());
        }
    }
}
